package io.renren.com.qywt.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.commons.mybatis.service.impl.CrudServiceImpl;
import io.renren.com.qywt.dao.AftersaleChanageRecordDao;
import io.renren.com.qywt.dto.AftersaleChanageRecordDTO;
import io.renren.com.qywt.entity.AftersaleChanageRecordEntity;
import io.renren.com.qywt.service.AftersaleChanageRecordService;
import io.renren.commons.security.context.TenantContext;
import io.renren.commons.security.user.SecurityUser;
import io.renren.commons.tools.utils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 客服工单变更记录表
 *
 * @author jiaohj 15110414840@139.com
 * @since 3.0 2022-09-20
 */
@Service
public class AftersaleChanageRecordServiceImpl extends CrudServiceImpl<AftersaleChanageRecordDao, AftersaleChanageRecordEntity, AftersaleChanageRecordDTO> implements AftersaleChanageRecordService {

    @Override
    public QueryWrapper<AftersaleChanageRecordEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<AftersaleChanageRecordEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(params.get("orderId")),"order_id",Long.parseLong(params.get("orderId").toString()));
        wrapper.eq("tenant_code", TenantContext.getTenantCode(SecurityUser.getUser()));
        wrapper.orderByDesc("create_date");
        return wrapper;
    }


    @Override
    public List<AftersaleChanageRecordDTO> getByOrderId(Map<String, Object> params) {
        List<AftersaleChanageRecordEntity> list=baseDao.selectList(this.getWrapper(params));
        return ConvertUtils.sourceToTarget(list,AftersaleChanageRecordDTO.class);
    }
}